if (!localStorage.getItem("computer") && !localStorage.getItem("mouse") && !localStorage.getItem("keybord") && !localStorage.getItem("louder")) {
    localStorage.setItem('computer', JSON.stringify(computer));
    localStorage.setItem('mouse', JSON.stringify(mouse));
    localStorage.setItem('keybord', JSON.stringify(keybord));
    localStorage.setItem('louder', JSON.stringify(louder));
    localStorage.setItem('carGo', JSON.stringify(carGo));
}
window.onload = function () {
    let arr1 = JSON.parse(localStorage.getItem('carGo'));
    $('.count').get(0).innerText = arr1.length;
}
var c = document.getElementById("canvase");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 10, 10);
// console.log(ctx)
var c = document.getElementById("canvase1");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 20, 10);
// console.log(ctx)
var c = document.getElementById("canvase2");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 30, 10);
// console.log(ctx)
var c = document.getElementById("canvase3");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 40, 10);
// console.log(ctx)
document.getElementsByClassName('shop')[0].onclick = function () {
    location.assign('./html/cargo.html')
    // window.alert(1)
}

$(document).on('click', '.goShop1', function () {
    let arr = JSON.parse(localStorage.getItem('computer'))[0];
    let arr1 = JSON.parse(localStorage.getItem('carGo'));
    console.log(arr1.length)
    if (arr1.length == 0) {
        arr1.push(arr);
        localStorage.setItem('carGo', JSON.stringify(arr1));
        $('.count').get(0).innerText = arr1.length;
        console.log($('.count').get(0).innerText)
    }
    else {
        let n = 0;
        for (let i = 0; i < arr1.length; i++) {
            if (arr1[i].id == arr.id) {
                n = 1;
            }
        }
        if (n == 0) {
            arr1.push(arr);
            localStorage.setItem('carGo', JSON.stringify(arr1));
            $('.count').get(0).innerText = arr1.length;
        }
        else {
            window.alert('该商品已在购物车中！！！');
        }
    }

})

$(document).on('click', '.goShop2', function () {
    let arr = JSON.parse(localStorage.getItem('mouse'))[0];
    let arr1 = JSON.parse(localStorage.getItem('carGo'));
    console.log(arr.id)
    if (arr1.length == 0) {
        arr1.push(arr);
        localStorage.setItem('carGo', JSON.stringify(arr1));
        $('.count').get(0).innerText = arr1.length;
        console.log($('.count').get(0).innerText)
    }
    else {
        let n = 0;
        for (let i = 0; i < arr1.length; i++) {
            if (arr1[i].id == arr.id) {
                n = 1;
            }
        }
        if (n == 0) {
            arr1.push(arr);
            localStorage.setItem('carGo', JSON.stringify(arr1));
            $('.count').get(0).innerText = arr1.length;
        }
        else if(n==1){
            window.alert('该商品已在购物车中！！！');
        }
    }

})



$(document).on('click', '.goShop3', function () {
    let arr = JSON.parse(localStorage.getItem('keybord'))[0];
    let arr1 = JSON.parse(localStorage.getItem('carGo'));
    console.log(arr.id)
    if (arr1.length == 0) {
        arr1.push(arr);
        localStorage.setItem('carGo', JSON.stringify(arr1));
        $('.count').get(0).innerText = arr1.length;
        console.log($('.count').get(0).innerText)
    }
    else {
        let n = 0;
        for (let i = 0; i < arr1.length; i++) {
            if (arr1[i].id == arr.id) {
                n = 1;
            }
        }
        if (n == 0) {
            arr1.push(arr);
            localStorage.setItem('carGo', JSON.stringify(arr1));
            $('.count').get(0).innerText = arr1.length;
        }
        else if(n==1){
            window.alert('该商品已在购物车中！！！');
        }
    }

})

$(document).on('click', '.goShop4', function () {
    let arr = JSON.parse(localStorage.getItem('louder'))[0];
    let arr1 = JSON.parse(localStorage.getItem('carGo'));
    console.log(arr.id)
    if (arr1.length == 0) {
        arr1.push(arr);
        localStorage.setItem('carGo', JSON.stringify(arr1));
        $('.count').get(0).innerText = arr1.length;
        console.log($('.count').get(0).innerText)
    }
    else {
        let n = 0;
        for (let i = 0; i < arr1.length; i++) {
            if (arr1[i].id == arr.id) {
                n = 1;
            }
        }
        if (n == 0) {
            arr1.push(arr);
            localStorage.setItem('carGo', JSON.stringify(arr1));
            $('.count').get(0).innerText = arr1.length;
        }
        else if(n==1){
            window.alert('该商品已在购物车中！！！');
        }
    }

})